﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace Demo05.ViewModels
{
    class MainPageViewModel : Common.BindableBase
    {
        public MainPageViewModel()
        {
            LoadData();

            var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(.1) };
            timer.Tick += (s, e) =>
            {
                var random = new Random((int)DateTime.Now.Ticks);
                foreach (var item in this.Items)
                {
                    item.X += random.Next(-3, 5);
                    item.Y += random.Next(-3, 5);
                }
            };
            timer.Start();
        }

        public void LoadData()
        {
            Items.Clear();
            for (int i = 0; i < 10; i++)
                this.Items.Add(Models.Item.Factory(i));
            this.Selected = this.Items.First();
        }

        ObservableCollection<Models.Item> _Items = new ObservableCollection<Models.Item>();
        public ObservableCollection<Models.Item> Items { get { return _Items; } }

        Models.Item _Selected = default(Models.Item);
        public Models.Item Selected { get { return _Selected; } set { SetProperty(ref _Selected, value); } }
    }
}
